package com.wll.android.drawp1;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class Practice2DrawCircleView extends View {
    Paint paint;

    public Practice2DrawCircleView(Context context) {
        super(context);
        init();
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);// 开启抗锯齿 ANTI_ALIAS_FLAG
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawCircle() 方法画圆
//        一共四个圆：1.实心圆 2.空心圆 3.蓝色实心圆 4.线宽为 20 的空心圆

//        paint.setColor(Color.YELLOW);
        canvas.drawCircle(328, 180, 164, paint);

        paint.setStyle(Paint.Style.STROKE);// 画线模式
//        paint.setColor(Color.CYAN);
        paint.setStrokeWidth(3);// 线条宽度为 3 像素
        canvas.drawCircle(720, 180, 164, paint);

        paint.setStyle(Paint.Style.FILL);// 填充模式
        paint.setColor(Color.BLUE);
        canvas.drawCircle(328, 560, 164, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(70);
//        paint.setAntiAlias(true);// 动态开启抗锯齿
        canvas.drawCircle(720, 560, 164, paint);
    }
}
